import axios from "axios"

import router from "./router"

axios.interceptors.request.use(
      config => {
            let token = localStorage.miniToken
            if (token) {
                 config.headers.Authorization = token
                 
            } else {
                  router.push("/login")
            }
            
            return config
      },
      err => {
            return Promise.reject(err)
      }
)

axios.interceptors.response.use(
      response => {
            let code = response.status
            
            if (code == 401) {
                  router.push("/login")
            }
            
            return response
      },
      err => {
            return Promise.reject(err)
      }
)

export default axios;